<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
  <th:block th:include="include :: header('财务运单列表')" />
  <th:block th:include="include :: bootstrap-select-css" />
</head>
<body class="gray-bg">
<div class="container-div">
  <div class="row">
    <div class="col-sm-10 search-collapse">
      <form id="formId">
        <div class="select-list">
          <ul>
            <li>
              <label>提验人：</label>
              <input type="text" id="vehicleInspector" name="vehicleInspector"/>
            </li>
            <li>
              <label>业务员：</label>
              <input type="text" id="userName" name="userName"/>
            </li>
            <li>
              <label>订单查询：</label>
              <input type="text" id="vehicleModel" name="vehicleModel"/>
            </li>
            <li>
              <label>运输结算：</label>
              <input type="text" id="transporter" name="transporter"/>
            </li>
            <li>
              <label>结算状态：</label>
              <select id="refund" name="refund">
                <option value="0">所有</option>
                <option value="1">有欠返</option>
                <option value="2">有欠付</option>
              </select>
            </li>
            <li>
              <label>支付方式：</label>
              <select name="payType" th:with="type=${@dict.getType('pay_type')}">
                <option value="">所有</option>
                <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
              </select>
            </li>
            <li>
              <label>订单状态：</label>
              <select name="orderType" th:with="type=${@dict.getType('order_type')}">
                <option value="">所有</option>
                <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
              </select>
            </li>
            <li class="select-time">
              <label>操作时间：</label>
              <input type="text" class="time-input" id="startTime" placeholder="开始时间" name="params[beginTime]"/>
              <span>-</span>
              <input type="text" class="time-input" id="endTime" placeholder="结束时间" name="params[endTime]"/>
            </li>
            <li>
              <a class="btn btn-primary btn-rounded btn-sm" onclick="searchPre()"><i class="fa fa-search"></i>&nbsp;搜索</a>
              <a class="btn btn-warning btn-rounded btn-sm" onclick="resetPre()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
            </li>
          </ul>
        </div>
      </form>
    </div>
    <div class="btn-group-sm" id="toolbar" role="group">
      <a id="hidDivS" class="btn btn-success" onclick="$.operate.salesmanAll()" shiro:hasPermission="system:order:edit">
        <i class="fa fa-plus"></i> 提成明细
      </a>
      <a id="hidDiv" class="btn btn-success" onclick="$.operate.settlementAll()" shiro:hasPermission="system:order:edit">
        <i class="fa fa-plus"></i> 批量结算
      </a>
      <!--      <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="system:finance:export">-->
      <!--        <i class="fa fa-download"></i> 导出-->
      <!--      </a>-->
    </div>
    <div class="col-sm-10 search-collapse">
      <div class="select-list">
        <ul>
          <li>
            <label style="margin: 0px 0px 0px 0px;">运费总金额：</label>
            <div class="col-sm-4" style="width: 0%;"  id="freightAmount">
            </div>
          </li>
          <li>
            <label style="margin: 0px 0px 0px 0px;">已付总金额：</label>
            <div class="col-sm-4" style="width: 0%;"  id="paidAmount">
            </div>
          </li>
          <li>
            <label style="margin: 0px 0px 0px 0px;">总利润：</label>
            <div class="col-sm-4" style="width: 0%;"  id="profit" >
            </div>
          </li>
          <li>
            <label style="margin: 0px 0px 0px 0px;">总提成：</label>
            <div class="col-sm-4" style="width: 0%;" id="commission">
            </div>
          </li>
          <li>
            <label style="margin: 0px 0px 0px 0px;">总提验费：</label>
            <div class="col-sm-4" style="width: 0%;" id="inspectionFee">
            </div>
          </li>
          <li>
            <label style="margin: 0px 0px 0px 0px;">总中介费：</label>
            <div class="col-sm-4" style="width: 0%;" id="agencyFee">
            </div>
          </li>
        </ul>
      </div>
    </div>
    <div class="col-sm-12 select-table table-striped">
      <table id="bootstrap-table">
      </table>
    </div>
  </div>
</div>
<th:block th:include="include :: footer" />
<th:block th:include="include :: bootstrap-select-js" />
<script th:inline="javascript">

  $(function(){
    var url = prefix + "/total";
    var dataParam = $.common.formToJSON("formId");
    $.post(url, dataParam, function(result) {
      if(result == "" || result == null){
        $("#freightAmount").html("0");
        $("#paidAmount").html("0");
        $("#profit").html("0");
        $("#commission").html("0");
        $("#inspectionFee").html("0");
        $("#agencyFee").html("0");
      }else {
        $("#freightAmount").html(result.freightAmount);
        $("#paidAmount").html(result.paidAmount);
        $("#profit").html(result.profit);
        $("#commission").html(result.commission);
        $("#inspectionFee").html(result.inspectionFee);
        $("#agencyFee").html(result.agencyFee);
      }
    });
  });

  document.getElementById('hidDiv').style.display='none';
  document.getElementById('hidDivS').style.display='none';

  var editFlag = [[${@permission.hasPermi('system:finance:edit')}]];
  var datasPay = [[${@dict.getType('pay_type')}]];
  var datasType = [[${@dict.getType('order_type')}]];
  var detailFlag = [[${@permission.hasPermi('system:finance:detail')}]];
  var completionFlag = [[${@permission.hasPermi('system:finance:completion')}]];
  var refundFlag = [[${@permission.hasPermi('system:finance:refund')}]];

  var prefix = ctx + "system/finance";


  $(function() {
    var options = {
      url: prefix + "/list",
      refundUrl: prefix + "/refund",
      completionUrl: prefix + "/completion",
      updateUrl: prefix + "/edit/{id}",
      exportUrl: prefix + "/export",
      detailUrl: prefix + "/detail/{id}",
      settlementUrl: prefix + "/settlement",
      detailedUrl : prefix + "/detailed/{id}",
      salesmanUrl: prefix + "/salesman/{id}",
      modalName: "财务运单",
      columns: [{
        checkbox: true
      },
        {
          field: 'id',
          title: '主键',
          visible: false
        },
        {
          field: 'orderId',
          title: '主键',
          visible: false
        },
        {
          field: 'createUser',
          title: '建单人'
        },
        {
          field: 'vehicleInspector',
          title: '提验人'
        },
        // {
        //   field: 'inspectionFee',
        //   title: '提验费'
        // },
        // {
        //   field: 'agencyFee',
        //   title: '中介费'
        // },
        {
          field: 'userName',
          title: '业务员'
        },
        {
          field: 'client',
          title: '委托人'
        },
        {
          field: 'clientPhone',
          title: '委托人电话'
        },
        {
          field: 'vehicleModel',
          title: '车型'
        },
        {
          field: 'vin',
          title: '车架号'
        },
        {
          field: 'origin',
          title: '起始地',
          formatter: function(value, row, index) {
            return $.table.tooltip(value, 6);
          }
        },
        {
          field: 'dest',
          title: '目的地',
          formatter: function(value, row, index) {
            return $.table.tooltip(value, 6);
          }
        },
        {
          field: 'receiverPhone',
          align: 'center',
          title: '接车人电话'
        },
        {
          field: 'freightAmount',
          align: 'center',
          title: '运费金额'
        },
        {
          field: 'paidAmount',
          align: 'center',
          title: '预付款'
        },
        {
          field: 'payType',
          title: '支付方式',
          align: 'center',
          formatter: function(value, row, index) {
            return $.table.selectDictLabel(datasPay, value);
          }
        },
        {
          field: 'orderType',
          title: '订单状态',
          align: 'center',
          formatter: function(value, row, index) {
            return $.table.selectDictLabel(datasType, value);
          }
        },
        {
          field: 'createTime',
          align: 'center',
          title: '建单日期',
          formatter: function(value, row, index) {
            return $.table.tooltip(value, 13);
          }
        }
      ]
    };
    $.table.init(options);
  });


  function totalA(){
    var transporter = $("#transporter").val();

    var url = prefix + "/total";
    var dataParam = $.common.formToJSON("formId");
    if(transporter.length > 0){
      dataParam = $.common.formToJSON("formId2");
    }
    $.post(url, dataParam, function(result) {
      if(result == "" || result == null){
        $("#freightAmount").html("0");
        $("#paidAmount").html("0");
        $("#profit").html("0");
        $("#commission").html("0");
        $("#inspectionFee").html("0");
        $("#agencyFee").html("0");
      }else {
        $("#freightAmount").html(result.freightAmount);
        $("#paidAmount").html(result.paidAmount);
        $("#profit").html(result.profit);
        $("#commission").html(result.commission);
        $("#inspectionFee").html(result.inspectionFee);
        $("#agencyFee").html(result.agencyFee);
      }
    });
  }

  function searchPre() {
    totalA();
    var refund = $("#refund").val();
    var transporter = $("#transporter").val();
    var userName = $("#userName").val();
    if(userName.length > 0 && transporter.length <= 0){
      document.getElementById('hidDivS').style.display='block';
    }
    if(transporter.length > 0 || refund > 0){
      $.table.showColumn("transporter");
      $.table.showColumn("transporterPhone");
      $.table.showColumn("plateNumber");
      $.table.showColumn("owes");
      $.table.showColumn("amount");
      $.table.showColumn("transferFee");
      $.table.showColumn("refund");
      document.getElementById('hidDiv').style.display='block';
      document.getElementById('hidDivS').style.display='none';

      $.table.hideColumn("profit");
      $.table.hideColumn("commission");
      $.table.hideColumn("notGive");
      $.table.hideColumn("notPay");
    }else {
      $.table.hideColumn("transporter");
      $.table.hideColumn("transporterPhone");
      $.table.hideColumn("plateNumber");
      $.table.hideColumn("owes");
      $.table.hideColumn("amount");
      $.table.hideColumn("transferFee");
      $.table.hideColumn("refund");
      document.getElementById('hidDiv').style.display='none';
      $.table.showColumn("profit");
      $.table.showColumn("commission");
      $.table.showColumn("notGive");
      $.table.showColumn("notPay");
    }
    $.table.search("formId");
  }

  function resetPre() {
    resetDate();
    $("#formId")[0].reset();
    $.table.hideColumn("transporter");
    $.table.hideColumn("transporterPhone");
    $.table.hideColumn("plateNumber");
    $.table.hideColumn("owes");
    $.table.hideColumn("amount");
    $.table.hideColumn("transferFee");
    $.table.hideColumn("refund");
    document.getElementById('hidDiv').style.display='none';
    document.getElementById('hidDivS').style.display='none';

    $.table.showColumn("profit");
    $.table.showColumn("commission");
    $.table.showColumn("notGive");
    $.table.showColumn("notPay");
    $.table.search();
    totalA();
  }
</script>
</body>
</html>